﻿using System;
using System.Collections.Generic;
using System.Text;
using Zhuang.Utility.Common.DataBase;
using System.Data;

namespace Zhuang.DAL
{
    public class Sys_Settings
    {

        public string GetValue(string moduleType, string name)
        {
            string value = null;
            string strSql = string.Format("select Value from Sys_Settings where ModuleType='{0}' and Name='{1}'", moduleType, name);
            DataTable dt = SqlHelper.Query(strSql).Tables[0];

            if(dt.Rows.Count>0)
            {
               value=dt.Rows[0][0].ToString();
            }
            return value;
        }

        public bool SetValue(string moduleType, string name, string value) 
        {

            string strSql = string.Format("update Sys_Settings set Value='{0}' where ModuleType='{1}' and Name='{2}'",value, moduleType, name);

            int iCount= SqlHelper.ExecuteSql(strSql);

            if (iCount > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool AddSetting(string moduleType, string name)
        {
            string strSql = string.Format("select count(*) from Sys_Settings where ModuleType='{0}' and Name ='{1}'", moduleType, name);

            if (Convert.ToInt32(SqlHelper.Query(strSql).Tables[0].Rows[0][0].ToString()) > 0)
            {
                return false;
            }

            strSql = string.Format("insert into Sys_Settings(ModuleType,Name) values('{0}','{1}')", moduleType, name);


            int iCount = SqlHelper.ExecuteSql(strSql);

            if (iCount > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
